#!/bin/sh

# Copy files
# merge config
# Enable whitelist
CURRENT_DIR=$(pwd)
PARBIN_DIR=/PowerHarmony/SMC/app
echo $CURRENT_DIR
echo $PARBIN_DIR

        echo "SmartProbe ed  Install"
        
        #appm -l -n EagleEyeSMG
        #appm -S -n EagleEyeSMG
        
        #systemctl stop znyw_eagleeyesmg
        #echo "1" > $PARBIN_DIR/EagleEyeSMG/otaEagleEyeSMG.ini
	#pkill EagleEyeSMG
        
	#mv $PARBIN_DIR/EagleEyeSMG $PARBIN_DIR/EagleEyeSMGbakbyOta
	chmod u+x EagleEyeSMG
	chmod u+x hm_nvr/start.sh
	mkdir $PARBIN_DIR/EagleEyeSMGbakbyOta
	cp -r $CURRENT_DIR/* $PARBIN_DIR/EagleEyeSMGbakbyOta
	
        cp $PARBIN_DIR/EagleEyeSMG/mqtt.db $PARBIN_DIR/EagleEyeSMGbakbyOta/mqtt.db
	mv /PowerHarmony/SMC/app/EagleEyeSMGbakbyOta/conf/EagleEyeSMG.ini /PowerHarmony/SMC/app/EagleEyeSMGbakbyOta/conf/EagleEyeSMG.ini.bak
        cp -r $PARBIN_DIR/EagleEyeSMG/conf/* /PowerHarmony/SMC/app/EagleEyeSMGbakbyOta/conf/
	rm /PowerHarmony/SMC/app/EagleEyeSMGbakbyOta/conf/EagleEyeSMG.ini
	mv /PowerHarmony/SMC/app/EagleEyeSMGbakbyOta/conf/EagleEyeSMG.ini.bak /PowerHarmony/SMC/app/EagleEyeSMGbakbyOta/conf/EagleEyeSMG.ini
        cp -r $PARBIN_DIR/EagleEyeSMG/conf/activation.json /PowerHarmony/SMC/sec/
        cp -r $PARBIN_DIR/EagleEyeSMG/conf/certs_client/* /PowerHarmony/SMC/sec/
        cp -r $PARBIN_DIR/EagleEyeSMG/iot_sec/* $PARBIN_DIR/EagleEyeSMGbakbyOta/iot_sec/
        cp -r $PARBIN_DIR/EagleEyeSMG/otaEagleEyeSMG.json $PARBIN_DIR/EagleEyeSMGbakbyOta/
	cp -r $PARBIN_DIR/EagleEyeSMG/nvr_EagleEyeSMG.ini $PARBIN_DIR/EagleEyeSMGbakbyOta/
       	
	#echo "1" > $PARBIN_DIR/EagleEyeSMG/otaEagleEyeSMG.ini
        #chmod u+x EagleEyeSMG
	#appm -s -n EagleEyeSMG
	#cp /PowerHarmony/SMC/app/EagleEyeSMG/hm_nvr/znyw_eagleeyesmg.service /lib/systemd/system/
	#systemctl daemon-reload
	#8.自启动
	#systemctl enable znyw_eagleeyesmg
	#9.启动
	#systemctl stop znyw_eagleeyesmg
	#systemctl start znyw_eagleeyesmg
	echo "1" > $PARBIN_DIR/EagleEyeSMGbakbyOta/otaEagleEyeSMG.ini
	
	pkill EagleEyeSMG #taiquzongduan use
	sleep 5
	#video use
	#reboot
	# 检查程序名称
	#program_name="EagleEyeSMG"

	# 使用 ps 命令查找程序
	# if ps -ef | grep -v grep | grep "$program_name" > /dev/null; then
	# 	#appm -u -n EagleEyeSMG
	#	echo "EagleEyeSMG Install completed successfully."    		
	# else
    	#	echo "0" > $PARBIN_DIR/EagleEyeSMG/otaEagleEyeSMG.ini
	#	mv $PARBIN_DIR/EagleEyeSMGbakbyOta $PARBIN_DIR/EagleEyeSMG
	#	
	#	#appm -s -n EagleEyeSMG
	#	
	# fi


#echo "EagleEyeSMG Install completed successfully."
exit 0

